package com.dbzf.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

public class JdbcUtil {
    private static DataSource dataSource;
    static {
        Properties properties = new Properties();
        try {
            InputStream is = JdbcUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
            System.out.println("InputStream:"+is);
            properties.load(is);
            dataSource = DruidDataSourceFactory.createDataSource(properties);
            //System.out.println(dataSource);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConn() {
        Connection connection = null;
        try {
            if(dataSource != null){
                connection = dataSource.getConnection();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
    }
}
